<template>
<div>
  <h1>个人信息</h1>
  <br/>
  <el-form :model="user" size="normal" :rules="rules" >
    <!--      prop中的名字和底下rules中的名字相对应-->
    <el-form-item prop="username" >
      用户名：<el-input v-model="user.username"  prefix-icon="el-icon-user" style="width: 20%"></el-input>
    </el-form-item>
    <el-form-item>
      昵称 ： <el-input v-model="user.nickName"  prefix-icon="el-icon-apple"  style="width: 20%"></el-input>
    </el-form-item>
    <el-form-item>
      年龄 ：<el-input v-model="user.age"  prefix-icon="el-icon-ship"  style="width: 20%"></el-input>
    </el-form-item>
    <el-form-item>
      性别 ： <el-input v-model="user.sex"  prefix-icon="el-icon-female" style="width: 20%" ></el-input>
    </el-form-item>
    <el-form-item>
      地址 ： <el-input v-model="user.address"  prefix-icon="el-icon-location" style="width: 20%"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="update" style="width: 5%;" >修改</el-button>
    </el-form-item>
  </el-form>
</div>
</template>

<script>
import request from "@/utils/request";

export default {
  name: "Person",
  data() {
    return {
      user :JSON.parse(sessionStorage.getItem('user'))
    }
  },
  methods:{
    update(){
      request.put('/api/user',this.user).then(res=>{
        console.log(res);
        if(res.code == '0'){
          this.$message({
            type : 'success',
            message :'更新成功'
          })
          this.dialogVisible = false
        }
        else {
          this.$message({
            type : 'error',
            message : res.msg
          })
        }
      })
      this.$router.push('/person')
    }

  }

}
</script>

<style scoped>

</style>